#!/bin/awk
function find_site_id(){
	for (i=1; i<=NF; i++) {
		if($i ~ "siteId="){
			return substr($i,8);
		}
	}
	return -1;
}
BEGIN {
	FS="^";
}
/\/x/ {
	siteId=find_site_id();
	a["pv",siteId] = a["pv",siteId] + 1;
	a["size",siteId] = a["size",siteId] + length($0)*8;
}
/\/e/ {
	siteId=find_site_id();
	a["click",siteId] = a["click",siteId] + 1;
	a["size",siteId] = a["size",siteId] + length($0)*8;
}
END {
	for ( ckey in a) {
		split(ckey,sepKey,SUBSEP);
		incmd="/home/data/stats/site/insql.sh " sepKey[2] " " sepKey[1] " " a[ckey] " " daytime;
		print "insql cmd: " incmd;
		print incmd | "/bin/bash";
	}
	print "end"
}
